package cc.zzone.controller;

import cc.zzone.bean.Result;
import cc.zzone.domain.PlatformData;
import org.springframework.web.bind.annotation.*;

/**
 * 平台认证接口
 *
 * @author jinzhengze
 * @since 2023年10月15日
 */
@RestController
@RequestMapping("/platform")
public class PlatformController {

    @RequestMapping(method = RequestMethod.GET)
    Object getData(@RequestParam(required = false) String id) {
        PlatformData data = PlatformData.mapper().getData(id);
        if (data == null)
            throw new RuntimeException("平台数据不存在");
        return Result.success(data);
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    Object queryData() {
        return Result.success(PlatformData.mapper().listData());
    }

    @RequestMapping(method = RequestMethod.PUT)
    Object updateData(@RequestBody PlatformData data) {
        if (data.getId() == null)
            throw new RuntimeException("配置对象ID不存在");
        data.setName(null);
        return Result.success(PlatformData.mapper().updateData(data));
    }
}
